import Vue from "vue"
import Vuex from "vuex"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //保证刷新页面无需登录
    shop_token: window.sessionStorage.getItem("shop_token"),
    customer_token: window.sessionStorage.getItem("customer_token"),
    customer_id: 0,
    transition: "van-slide-left"
  },
  mutations: {
    SET_CUSTOMER_ID: (state, data) => {
      state.customer_id = data
    },
    SET_SHOP_TOKEN: (state, data) => {
      state.shop_token = data
      window.sessionStorage.setItem("shop_token", data)
    },
    SET_CUSTOMER_TOKEN: (state, data) => {
      state.customer_token = data
      window.sessionStorage.setItem("customer_token", data)
    },
    CUSTOMER_LOGOUT: state => {
      state.customer_token = null
      window.sessionStorage.removeItem("customer_token")
    },
    SHOP_LOGOUT: state => {
      state.shop_token = null
      window.sessionStorage.removeItem("shop_token")
    },
    SET_TRANSITION: (state, dir) => {
      if (dir.length > 0) state.transition = "slide-" + dir
      else state.transition = ""
    }
  },
  actions: {}
})
